//
//  MeFiveImageCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/27.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

protocol MeFiveImageCellDeleage : NSObjectProtocol {
    
    func meFiveImageCellBtnDidTap(str: String)
    
}


class MeFiveImageCell: BaseTableViewCell {
    
    @IBOutlet weak var imageView1: UIImageView!
    @IBOutlet weak var imageView2: UIImageView!
    @IBOutlet weak var imageView3: UIImageView!
    @IBOutlet weak var imageView4: UIImageView!
    @IBOutlet weak var imageView5: UIImageView!
    @IBOutlet weak var label1: UILabel!
    @IBOutlet weak var label2: UILabel!
    @IBOutlet weak var label3: UILabel!
    @IBOutlet weak var label4: UILabel!
    @IBOutlet weak var label5: UILabel!
    @IBOutlet weak var topLabel1: UILabel!
    @IBOutlet weak var topLabel2: UILabel!
    @IBOutlet weak var topLabel3: UILabel!
    @IBOutlet weak var topLabel4: UILabel!
    @IBOutlet weak var topLabel5: UILabel!
    @IBOutlet weak var btn1: UIButton!
    @IBOutlet weak var btn2: UIButton!
    @IBOutlet weak var btn3: UIButton!
    @IBOutlet weak var btn4: UIButton!
    @IBOutlet weak var btn5: UIButton!
    
    @IBOutlet weak var constr1: NSLayoutConstraint!
    
    @IBOutlet weak var constr2: NSLayoutConstraint!

    @IBOutlet weak var constr3: NSLayoutConstraint!
    @IBOutlet weak var constr4: NSLayoutConstraint!
    
    @IBOutlet weak var constr5: NSLayoutConstraint!
    
    weak var delegate : MeFiveImageCellDeleage?
    
    
    var model : PersonalDataModel?{
        
        didSet{
            
            if model == nil {
                return
            }
            
            if model!.order_nopay_count == "0" {
                topLabel1.isHidden = true
                
            } else {
                topLabel1.isHidden = false
                
                var number = Int(model!.order_nopay_count) ?? 0
                
                if number > 99 {
                    model!.order_nopay_count = "99"
                    number = 99
                }
                
                if number > 9 && number < 100 {
                    
                    constr1.constant = 18
                    
                    
                } else {
                    
                    constr1.constant = 14
                    
                    
                }
                
                topLabel1.text = model!.order_nopay_count
                
                
            }
            
            
            if model!.order_nosend_count == "0" {
                topLabel2.isHidden = true
                
            } else {
                topLabel2.isHidden = false
                
                var number = Int(model!.order_nosend_count) ?? 0
                
                if number > 99 {
                    model!.order_nosend_count = "99"
                    number = 99
                }
                
                if number > 9 && number < 100 {
                    
                    constr2.constant = 18
                    
                    
                } else {
                    
                    constr2.constant = 14
                    
                    
                }
                
                topLabel2.text = model!.order_nosend_count
                

                
            }
            
            
            
            if model!.order_notakes_count == "0" {
                topLabel3.isHidden = true
                
            } else {
                topLabel3.isHidden = false
                
                var number = Int(model!.order_notakes_count) ?? 0
                
                if number > 99 {
                    model!.order_notakes_count = "99"
                    number = 99
                }
                
                if number > 9 && number < 100 {
                    
                    constr3.constant = 18
                    
                    
                } else {
                    
                    constr3.constant = 14
                    
                    
                }
                
                topLabel3.text = model!.order_notakes_count
                
                
                
            }
            
            
            
            if model!.order_noeval_count == "0" {
                topLabel4.isHidden = true
                
            } else {
                topLabel4.isHidden = false
                
                var number = Int(model!.order_noeval_count) ?? 0
                
                if number > 99 {
                    model!.order_noeval_count = "99"
                    number = 99
                }
                
                if number > 9 && number < 100 {
                    
                    constr4.constant = 18
                    
                    
                } else {
                    
                    constr4.constant = 14
                    
                    
                }
                
                topLabel4.text = model!.order_noeval_count
                
                

                
            }
            
            
            
            
            if model!.return_count == "0" {
                topLabel5.isHidden = true
                
            } else {
                topLabel5.isHidden = false
                
                var number = Int(model!.return_count) ?? 0
                
                if number > 99 {
                    model!.return_count = "99"
                    number = 99
                    
                }
                
                if number > 9 && number < 100 {
                    
                    constr5.constant = 18
                    
                    
                } else {
                    
                    constr5.constant = 14
                    
                    
                }
                
                topLabel5.text = model!.return_count

                
            }
            
            
            
        }
        
         
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        topLabel1.addCornerAndBorder(borderColor: UIColor.white, borderWidth: 0.5, masksToBounds: true, cornerRadius: 7)
        topLabel2.addCornerAndBorder(borderColor: UIColor.white, borderWidth: 0.5, masksToBounds: true, cornerRadius: 7)
        topLabel3.addCornerAndBorder(borderColor: UIColor.white, borderWidth: 0.5, masksToBounds: true, cornerRadius: 7)
        topLabel4.addCornerAndBorder(borderColor: UIColor.white, borderWidth: 0.5, masksToBounds: true, cornerRadius: 7)
        topLabel5.addCornerAndBorder(borderColor: UIColor.white, borderWidth: 0.5, masksToBounds: true, cornerRadius: 7)
        label1.textColor = UIColor.dakGray()
        label2.textColor = UIColor.dakGray()
        label3.textColor = UIColor.dakGray()
        label4.textColor = UIColor.dakGray()
        label5.textColor = UIColor.dakGray()
        // Initialization code
    }
    
    
    @IBAction func btn1DidTap(_ sender: UIButton) {
        
        delegate?.meFiveImageCellBtnDidTap(str: label1.text!)
        
    }
    
    @IBAction func btn2DidTap(_ sender: UIButton) {
        
        delegate?.meFiveImageCellBtnDidTap(str: label2.text!)

    }
    
    @IBAction func btn3DidTap(_ sender: UIButton) {
        
        delegate?.meFiveImageCellBtnDidTap(str: label3.text!)

    }
    
    @IBAction func btn4DidTap(_ sender: UIButton) {
        
        delegate?.meFiveImageCellBtnDidTap(str: label4.text!)

    }
    
    @IBAction func btn5DidTap(_ sender: UIButton) {
        
        delegate?.meFiveImageCellBtnDidTap(str: label5.text!)

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        
        super.setSelected(selected, animated: animated)

    }
    
}
